<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>reg</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link href="css/Login.css" rel="stylesheet" type="text/css" />
</head>
<script language="JavaScript">
	function isEmail(str) {
		var reg = /(^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$)|(^$)/;
		if (!reg.test(str)) {
			return false;
		}
		return true;
	}
	function isPhoneNumber(str) {
		var phone = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
		if (!phone.test(str)) {
			return false;
		}
		return true;
	}
	function checkit() {
		var theForm;
		theForm = document.regForm;
		if (theForm.user_id.value == "") {
			alert("请输入账号！");
			theForm.user_id.focus();
			return false;
		}
		if (theForm.password.value == "") {
			alert("密码不能为空！");
			theForm.password.focus();
			return false;
		}
		if (theForm.rpassword.value == ""
				|| theForm.rpassword.value != theForm.password.value) {
			alert("前后两次输入的密码不一致！");
			theForm.rpassword.focus();
			return false;
		}
		if (theForm.user_name.value == "") {
			alert("请输入姓名！");
			theForm.user_name.focus();
			return false;
		}
		if (theForm.phone_number.value == "") {
			alert("电话号码不能为空！");
			theForm.phone_number.focus();
			return false;
		}
		if (!isPhoneNumber(theForm.phone_number.value)) {
			alert("电话号码格式不正确！");
			theForm.phone_number.focus();
			return false;
		}
		if (theForm.email.value == "") {
			alert("邮箱不能为空！");
			theForm.email.focus();
			return false;
		}
		if (!isEmail(theForm.email.value)) {
			alert("邮箱格式不正确！");
			theForm.email.focus();
			return false;
		}
		theForm.submit();
	}
</script>
<body>
	<div class="center jiao">
		<form name="regForm"
			action="${pageContext.request.contextPath}/user/reg" method="post">
			<table class="reg_table">
				<tbody>
					<tr>
						<td class="first_td"><b>账号：</b></td>
						<td class="second_td"><input type="text" name="user_id"
							style="width:150px;" size="20"></td>
					</tr>
					<tr>
						<td class="first_td"><b>姓名：</b></td>
						<td class="second_td"><input type="text" name="user_name"
							style="width:150px;" size="20"></td>
					</tr>
					<tr>
						<td class="first_td"><b>密码：</b></td>
						<td class="second_td"><input type="password" name="password"
							style="width:150px;" size="20"></td>
					</tr>
					<tr>
						<td class="first_td"><b>重复密码：</b></td>
						<td class="second_td"><input type="password" name="rpassword"
							style="width:150px;" size="20"></td>
					</tr>
					<tr>
						<td class="first_td"><b>电话号码：</b></td>
						<td class="second_td"><input type="text" name="phone_number"
							style="width:150px;" size="20"></td>
					</tr>
					<tr>
						<td class="first_td"><b>邮箱：</b></td>
						<td class="second_td"><input type="text" name="email"
							style="width:150px;" size="20"></td>
					</tr>
					<tr>
						<td class="first_td">验证码：</td>
						<td class="second_td"><img border=0 height=24
							src="${pageContext.request.contextPath}/jsp/code.jsp" /><input
							class="codeinput" type="text" name="code" maxlength="4"
							style="width:78px;" /></td>
					</tr>
					<tr>
						<td style="text-align:right;"><input type="button" value="提交"
							class="but_login" name="Submit" onclick="checkit()"></td>
						<td style="text-align:center;"><input type="reset" value="重填"
							class="but_reg" name="Submit2"></td>
					</tr>
					<tr>
						<td></td>
						<td>
							<%
								String message = (String) session.getAttribute("msg");
								if ("failed".equals(message)) {
									out.print("账号已被注册!");
								} else if ("codeWrong".equals(message)) {
									out.print("验证码错误!");
								}
								session.setAttribute("msg", "");
							%>
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
	<%@ include file="footer.html"%>
</body>
</html>
